package com.sdp.right.task;

import java.time.LocalDate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sdp.right.cron.ScheduledOfTask;
import com.sdp.right.db.sys_login_log.service.ISysLoginLogService;
import com.sdp.right.entity.SysLoginLog;

@Component
public class CleanLoginLogTask implements ScheduledOfTask{
	
	@Autowired
	private ISysLoginLogService iSysLoginLogService;

	@Override
	@Transactional(rollbackFor=Exception.class)
	public void execute() {
		//登录日志，最多保留120天
		LambdaQueryWrapper<SysLoginLog> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.le(SysLoginLog::getLoginTime, LocalDate.now().plusDays(-120));
		iSysLoginLogService.remove(queryWrapper);
		
	}

}
